import { min } from "lodash"
/** 毫秒转换为时分秒 */
export const toHHmmss = (time: number) => {
    if (!time) {
        return ''
    }
    let hours: string | number = Math.floor(time / (3600 * 1000))
    hours = hours < 10 ? `0${hours}` : hours
    let minutes: string | number = Math.floor(time / (3600 * 1000 * 60))
    minutes = minutes < 10 ? `0${minutes}` : minutes
    let seconds: string | number = Math.floor(time % (1000 * 3600))
    seconds = seconds < 10 ? `0${seconds}` : seconds
    return `${hours}:${minutes}:${seconds}`
}

export const dateFormat = (time: number, format?: string) => {
    if (!time) {
        return ''
    }
    format = format || 'yyyy-MM-dd hh:mm:ss'
    const date = new Date(time)
    const o: any = {
        'M+': date.getMonth() + 1,
        'd+': date.getDate(),
        'h+': date.getHours(),
        'm+': date.getMinutes(),
        's+': date.getSeconds(),
        'q+': Math.floor((date.getMonth() + 3) / 3),
        'S': date.getMilliseconds()
    }
    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))

    }
    for (const key in o) {
        if (new RegExp('(' + key + ')').test(format)) {
            format.replace(RegExp.$1, (RegExp.$1.length == 1) ? o[key] : ('00' + o[key]).substr(('' + o[key]).length))
        }
    }
    return format
}